class Event {
  constructor() {
    this.handles = {}
  }
  on(type, handle) { //订阅
    if (!(type in this.handles)) {
      console.log(type)
      this.handles[type] = []
    } else {
      this.handles[type].push(handle)
    }
    console.log('on', this.handles)
  }
  emit(type, ...args) {
    this.handles[type].forEach((fn) => fn(...args))
  }

  remove(type, handle) { // 移除监听
    if (!type in this.handles) return new Error('无效事件')
    if (!handle) delete this.handles[type] // 若没有具体指明哪个时间，则全部移除
    this.handles[type] = this.handles[type].filter((item) => item !== handle)
    console.log('remove', this.handles)
  }
}


function load(params) {
  console.log('load', params)
}

function foo(params) {
  console.log('foo...', params)
}

var newevent = new Event();
newevent.on('load', load);
newevent.on('load', foo);

// 触发
newevent.emit('load', 'load触发')

// 移除foo
newevent.remove('load', foo);